package com.nut.lmsc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.lmsc.api.req.CircleQueryReq;
import com.nut.lmsc.common.Result;
import com.nut.lmsc.entity.Circle;
import com.nut.lmsc.mapper.CircleMapper;
import com.nut.lmsc.service.CircleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Slf4j
@Service
public class CircleServiceImpl implements CircleService {

    @Autowired
    private CircleMapper circleMapper;

    @Override
    public Result<List<Circle>> list() {
        LambdaQueryWrapper<Circle> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Circle::getStatus, 1);
        List<Circle> list = circleMapper.selectList(queryWrapper);
        return Result.ok(list);
    }

    @Override
    public Result<IPage<Circle>> listPage(CircleQueryReq req) {
//        IPage<Circle> list = circleMapper.listPage(req.newPage(), req.getTitle(),
//                req.getStatus(), req.getType());
//        return Result.ok(list);

        return Result.ok();
    }

    @Override
    public Result<Circle> getById(Integer id) {
        Circle circle = circleMapper.selectById(id);
        if (circle == null) {
            return Result.fail("未找到导航图片信息");
        }
        return Result.ok(circle);
    }

    @Override
    public Result add(Circle circle) {
        circleMapper.insert(circle);
        return Result.ok(circle.getId());
    }

    @Override
    public Result updateById(Circle circle) {
        circleMapper.updateById(circle);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        circleMapper.deleteBatchIds(ids);
        return Result.ok();
    }
}
